<?php

namespace App\Http\Resources\user;

use App\Models\fund\Coupon;
use Illuminate\Http\Resources\Json\ResourceCollection;

class CouponPageCollection extends ResourceCollection
{
    /**
     * Transform the resource into an array.
     *
     * @param \Illuminate\Http\Request $request
     * @return array
     */
    public function toArray($request)
    {

        return [
            'total' => $this->resource->total(),
            'perPage' => $this->resource->perPage(),
            'current_page' => $this->resource->currentPage(),
            'items' => $this->collection->map(function (Coupon $item) {
                return [
                    'id' => $item->id,
                    'amount' => $item->amount,
                    'title' => $item->title,
                    'quota' => $item->quota,
                    'end_at' => $item->end_at,
                    'status' => $item->status,
                    'status_text' => $item->status_text,
                ];
            })
        ];

    }
}
